// GTY

#pragma once

#include "CoreMinimal.h"
#include "GameplayTagContainer.h"
#include "GameFramework/PlayerController.h"
#include "AuraPlayerController.generated.h"

class AMagicCircle;
class UNiagaraSystem;
class UDamageTextComponent;
class USplineComponent;
class UAuraInputConfig;
class UInputMappingContext;
class UInputAction;
struct FInputActionValue;
class IEnemyInterface;
class UAuraAbilitySystemComponent;

/**
 * 
 */
UCLASS()
class AURAGAME_API AAuraPlayerController : public APlayerController
{
	GENERATED_BODY()

public:
	AAuraPlayerController();
	virtual void Tick(float DeltaTime) override;

	UFUNCTION(Client, Reliable)
	void ShowDamageNumber(float DamageAmount, ACharacter* TargetCharacter, bool IsBlockedHit, bool IsCriticalHit); //在每个客户端显示伤害数值


	//显示魔法光圈 并设置光圈贴花材质
	UFUNCTION(BlueprintCallable)
	void ShowMagicCircle(UMaterialInterface* DecalMaterial);

	//隐藏魔法光圈
	UFUNCTION(BlueprintCallable)
	void HideMagicCircle() const; 

protected:
	virtual void BeginPlay() override;
	virtual void SetupInputComponent() override;// 输入绑定

private:
	UPROPERTY(EditAnywhere, Category = "Input")
	TObjectPtr<UInputMappingContext> AuraContext;// 输入映射

	UPROPERTY(EditAnywhere, Category = "Input")
	TObjectPtr<UInputAction> MoveAction;// 移动

	UPROPERTY(EditAnywhere, Category = "Input")
	TObjectPtr<UInputAction> ShiftAction;

	void ShiftPressed(){bShiftKeyDown = true;}
	void ShiftReleased(){bShiftKeyDown = false;}
	bool bShiftKeyDown = false;

	void Move(const   FInputActionValue& InputActionValue);

	void CursorTrace();// 鼠标追踪

	/*视频教程报错，视频中剥离智能指针？？？？？*/
	//TObjectPtr<IEnemyInterface> LastActor;// 上一个追踪对象
	//TObjectPtr<IEnemyInterface> ThisActor;// 当前追踪对象
	IEnemyInterface* LastActor;
	IEnemyInterface* ThisActor;
	//TObjectPtr<AActor> LastActor;
	//TObjectPtr<AActor> ThisActor;
	

	FHitResult CursorHit;// 创建一个 hit 结果对象



	UPROPERTY(EditAnywhere, Category = "Input")
	TObjectPtr<UAuraInputConfig> InputConfig;


	void AbilityInputTagPressed(FGameplayTag InputTag);// 按下    InputTag就是我按下的键
	void AbilityInputTagReleased(FGameplayTag InputTag);// 释放
	void AbilityInputTagHeld(FGameplayTag InputTag);// 保持

	UPROPERTY()
	TObjectPtr<UAuraAbilitySystemComponent> AuraAbilitySystemComponent;

	UAuraAbilitySystemComponent* GetASC();

	//鼠标移动
	FVector CachedDestination = FVector::ZeroVector;// 缓存目的地
	float FollowTime = 0.f;// 追踪时间
	bool bAutoRunning = false; //当前是否自动移动
	bool bTargeting = false; //当前鼠标是否选中敌人

	UPROPERTY(EditDefaultsOnly)
	float ShortPressThreshold = 0.5f; //定义鼠标悬停多长时间内算点击事件

	UPROPERTY(EditDefaultsOnly)
	float AutoRunAcceptanceRadius = 50.f; //当角色和目标距离在此半径内时，将关闭自动寻路

	UPROPERTY(VisibleAnywhere)
	TObjectPtr<USplineComponent> Spline; //自动寻路时生成的样条线

	UPROPERTY(EditDefaultsOnly)
	TObjectPtr<UNiagaraSystem> ChickNiagaraSystem;
	
	void AutoRun();

	UPROPERTY(EditDefaultsOnly)
	TSubclassOf<UDamageTextComponent> DamageTextComponentClass;

	//创建奥数光圈使用的类
	UPROPERTY(EditDefaultsOnly)
	TSubclassOf<AMagicCircle> MagicCircleClass;

	//存储魔法光圈的属性，不需要暴露给蓝图
	UPROPERTY()
	TObjectPtr<AMagicCircle> MagicCircle;

	void UpdateMagicCircleLocation() const; //每一帧调用，更新魔法光圈的位置

	
};


